uniform sampler2D tex_pp0, tex_pp1, tex_depth;

float get_sample(vec2 coord, float compare_depth)
{
	float t_sample = texture2D(tex_pp1, coord).r;
	float t_depth = texture2D(tex_depth, coord).r;

	float dd = max(compare_depth - t_depth, 0.0);
	if (dd > 0.05)
		return 1.0;
	else
		return t_sample;
}

float blur_ssao(float blur_radius)
{
	float t_depth = texture2D(tex_depth, gl_TexCoord[0].st).r;

	float result = 0.0;

	result += get_sample(gl_TexCoord[0].st+vec2(-blur_radius, -blur_radius), t_depth);
	result += get_sample(gl_TexCoord[0].st+vec2( blur_radius, -blur_radius), t_depth);
	result += get_sample(gl_TexCoord[0].st+vec2( blur_radius,  blur_radius), t_depth);
	result += get_sample(gl_TexCoord[0].st+vec2(-blur_radius,  blur_radius), t_depth);

	return result / 4.0;
}

void main (void)
{
	vec4 t_out0 = texture2D(tex_pp0, gl_TexCoord[0].st);
	vec4 t_out1 = texture2D(tex_pp1, gl_TexCoord[0].st);
	//vec4 t_out2 = texture2D(tex_depth, gl_TexCoord[0].st);
	//gl_FragColor = t_out2;
	gl_FragColor = blur_ssao(0.004) * t_out0;
	//gl_FragColor = t_out1;//blur_ssao(0.001);// * t_out0;
}